﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows.Forms;
using System.Data.SqlClient;
using HotelManager.DataAccess;
using HotelManager.Model;
namespace HotelManager.View
{
    public partial class FormSuDungDV : Form
    {
        SuDungDvAccess sudungdvAccess = new SuDungDvAccess();
        DataTable dsDichvu = new DataTable();
        public FormSuDungDV()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Bạn có chắc muốn thoát không?", "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            this.Close();
        }

        private void txtMadichvu_TextChanged(object sender, EventArgs e)
        {

        }

        private void btnThem_Click(object sender, EventArgs e)
        {
         DichVu dv = new DichVu(txtMadichvu.Text, txtTendichvu.Text, txtGia.Text, txtMaphong.Text, txtNguoiquanly.Text );
            if (sudungdvAccess.themDichVu(dv) == 0) {MessageBox.Show("Mã dịch vụ tồn tại");}
            else 
            {
                MessageBox.Show("Them thanh cong");
            }
            FormSuDungDV_Load(sender, e );
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            DichVu dv = new DichVu(txtMadichvu.Text, txtTendichvu.Text, txtGia.Text, txtMaphong.Text, txtNguoiquanly.Text );
            if (sudungdvAccess.suaDichVu(dv) == 0) {MessageBox.Show("Ma dich vu khong ton tai");}
            else
            {
                MessageBox.Show("Sua thanh cong!");
            }
            FormSuDungDV_Load(sender, e);
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
        DichVu dv = new DichVu(txtMadichvu.Text, txtTendichvu.Text, txtGia.Text, txtMaphong.Text, txtNguoiquanly.Text );
            if (sudungdvAccess.xoadv(dv)==0)
            {
                MessageBox.Show("Ma dich vu khong ton tai");
            }
            else
            {
                MessageBox.Show("Xoa thanh cong");
            }
            FormSuDungDV_Load(sender, e);
        }

        private void txtTimkiem_TextChanged(object sender, EventArgs e)
        {
        DataView dataView = new DataView();
            if (cbbTimkiem.SelectedItem == cbbTimkiem.Items[0])
            {
                dataView = sudungdvAccess.timkiemMadv(txtTimkiem.Text);
                dataGridView1.DataSource = dataView;
            }
            else 
            {
                dataView = sudungdvAccess.timkiemTendv(txtTimkiem.Text);
                dataGridView1.DataSource = dataView;
            }
        }

        private void cbbTimkiem_SelectedIndexChanged(object sender, EventArgs e)
        {
        
        }

        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            txtMadichvu.Text = dataGridView1.CurrentRow.Cells[0].Value.ToString();
            txtTendichvu.Text = dataGridView1.CurrentRow.Cells[1].Value.ToString();
            txtMaphong.Text = dataGridView1.CurrentRow.Cells[2].Value.ToString();
            txtMaso.Text = dataGridView1.CurrentRow.Cells[3].Value.ToString();
            txtNguoiquanly.Text = dataGridView1.CurrentRow.Cells[4].Value.ToString();
            txtGia.Text = dataGridView1.CurrentRow.Cells[5].Value.ToString();
        
        }

    }
    
}
